﻿using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.DHQG;
using DHQGHN.DAL.Models.DHQG;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DHQGHN.DAL.BO.DHQG
{
    public class ChiTieuBO : BaseBO
    {
        private ChiTieuDAO _dao;

        public const string CHI_TIEU_ID = "CHI_TIEU_ID";
        public const string MA = "MA";
        public const string CAP = "CAP";
        public const string MA_CAP1 = "MA_CAP1";
        public const string MA_CAP2 = "MA_CAP2";
        public const string MA_CAP3 = "MA_CAP3";
        public const string TEN_CHI_TIEU = "TEN_CHI_TIEU";
        public const string TEN_CHI_TIEU_CAP1 = "TEN_CHI_TIEU_CAP1";
        public const string TEN_CHI_TIEU_CAP2 = "TEN_CHI_TIEU_CAP2";
        public const string TEN_CHI_TIEU_CAP3 = "TEN_CHI_TIEU_CAP3";
        public const string GHI_CHU = "GHI_CHU";
        public const string DELELED = "DELETED";
        public const string START_DATE = "START_DATE";
        public const string END_DATE = "END_DATE";
        public const string LAST_UPDATED = "LAST_UPDATED";
        public const string TYPE = "TYPE";
        public const string LA_CHI_TIEU_AO = "LA_CHI_TIEU_AO";
        public const string CHO_PHEP_TINH_TONG = "CHO_PHEP_TINH_TONG";
        public const string DON_VI_TINH = "DON_VI_TINH";
        public const string DON_VI_ID = "DON_VI_ID";
        public const string RECORD_COUNT = "RECORD_COUNT";

        public ChiTieuBO()
        {
            _dao = new ChiTieuDAO(Common.ConnectionUtil.DHQGHN_CONNECTION_STRING, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<ChiTieu> GetListPaging(ChiTieu mode, int pageIndex, int pageSize)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetListPaging(mode, pageIndex, pageSize, mapDictionary);
            }
            catch
            {
                throw;
            }
        }
        public List<ChitieuNew> GetalllistbynamchitieubydonviGiuanam(int namchitieuid, int madonvi,int nguoidungid)
        {
            try
            {
                return _dao.GetalllistbynamchitieubydonviGiuanam(namchitieuid, madonvi, nguoidungid);
            }
            catch
            {
                throw;
            }
        }
        public List<ChitieuNew> Getlistkhthchitieu(int namkh, int mocks, int donvi, int nguoidungid)
        {
            try
            {
                return _dao.Getlistkhthchitieu(namkh, mocks, donvi,nguoidungid);
            }
            catch
            {
                throw;
            }
        }
        public ChitieuNew GetChitieubyMacap1(int macap1)
        {
            try
            {
                return _dao.GetChitieubyMacap1(macap1);
            }
            catch
            {
                throw;
            }
        }
        public List<ChitieuNew> Getlistkhthchitieudachot(int namkh, int mocks, int donvi,int nguoidungid)
        {
            try
            {
                return _dao.Getlistkhthchitieudachot(namkh, mocks, donvi,nguoidungid);
            }
            catch
            {
                throw;
            }
        }
        public List<ChitieuNew> GETCAP1(int namchitieuid)
        {
            try
            {
                return _dao.GETCAP1(namchitieuid);
            }
            catch
            {
                throw;
            }
        }
        public bool Save(ChiTieu model)
        {
            try
            {
                return _dao.Save(model);
            }
            catch
            {
                throw;
            }
        }
        public List<ChitieuNew> Getallchitieurieng(int dvid)
        {
            try
            {
                return _dao.Getallchitieurieng(dvid);
            }
            catch
            {
                throw;
            }
        }
        public bool Delete(int id)
        {
            try
            {
                return _dao.Delete(id);
            }
            catch
            {
                throw;
            }
        }

        public ChiTieu GetById(int id)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetById(id, mapDictionary);
            }
            catch
            {
                throw;
            }
        }
        public List<ChitieuNew> Getallchitieubymacap2(int namchitieuid, int macap2)
        {
            try
            {
                return _dao.Getallchitieubymacap2(namchitieuid, macap2);
            }
            catch
            {
                throw;
            }
        }
        public List<ChitieuNew> Getall()
        {
            try
            {
                return _dao.Getalllist();
            }
            catch
            {
                throw;
            }

        }
        public List<ChitieuNew> Getalllistbynamchitieu(int namchitieuid, int madonvi)
        {
            try
            {
                return _dao.Getalllistbynamchitieu(namchitieuid, madonvi);
            }
            catch
            {
                throw;
            }
        }
        public List<ChitieuNew> Getalllistbynamchitieubydonvi(int namchitieuid, int madonvi, int nguoidungid)
        {
            try
            {
                return _dao.Getalllistbynamchitieubydonvi(namchitieuid, madonvi,nguoidungid);
            }
            catch
            {
                throw;
            }
        }

        public List<ChiTieu> GetByMaCap1_Cap(int cap, string maCap1)
        {
            try
            {
                return _dao.GetByMaCap1_Cap(cap, maCap1);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public ChitieuNew GetCap2ByMaCap2_Cap(int cap, string maCap2)
        {
            try
            {
                return _dao.GetCap2ByMaCap2_Cap(cap, maCap2);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public List<ChiTieu> GetByCap(int cap)
        {
            try
            {
                return _dao.GetByCap(cap);
            }
            catch
            {
                throw;
            }
        }


        public long GetMaxMaCap1()
        {
            try
            {
                return _dao.GetMaxMaCap1();
            }
            catch
            {
                throw;
            }
        }

        public long GetMaxMaCap2()
        {
            try
            {
                return _dao.GetMaxMaCap2();
            }
            catch
            {
                throw;
            }
        }

        public long GetMaxMaCap3()
        {
            try
            {
                return _dao.GetMaxMaCap3();
            }
            catch
            {
                throw;
            }
        }

        public List<ChitieuNew> GetByNguoiDungId(int nguoiDungId, int namKHId)
        {
            try
            {
                return _dao.GetByNguoiDungId(nguoiDungId, namKHId);
            }
            catch
            {
                throw;
            }
        }

        private Dictionary<string, string> GetMapDictionary()
        {
            Dictionary<string, string> mapDictionary = new Dictionary<string, string>()
            {
                {ChiTieu.FIELD_CHI_TIEU_ID, ChiTieuBO.CHI_TIEU_ID},
                {ChiTieu.FIELD_CAP, ChiTieuBO.CAP},                
                {ChiTieu.FIELD_DELELED, ChiTieuBO.DELELED},
                {ChiTieu.FIELD_END_DATE, ChiTieuBO.END_DATE},
                {ChiTieu.FIELD_GHI_CHU, ChiTieuBO.GHI_CHU},
                {ChiTieu.FIELD_LAST_UPDATED, ChiTieuBO.LAST_UPDATED},
                {ChiTieu.FIELD_MA, ChiTieuBO.MA},
                {ChiTieu.FIELD_MA_CAP1, ChiTieuBO.MA_CAP1},
                {ChiTieu.FIELD_MA_CAP2, ChiTieuBO.MA_CAP2},
                {ChiTieu.FIELD_MA_CAP3, ChiTieuBO.MA_CAP3},
                {ChiTieu.FIELD_START_DATE, ChiTieuBO.START_DATE},
                {ChiTieu.FIELD_TEN_CHI_TIEU, ChiTieuBO.TEN_CHI_TIEU},
                {ChiTieu.FIELD_TEN_CHI_TIEU_CAP1, ChiTieuBO.TEN_CHI_TIEU_CAP1},
                {ChiTieu.FIELD_TEN_CHI_TIEU_CAP2, ChiTieuBO.TEN_CHI_TIEU_CAP2},
                {ChiTieu.FIELD_TEN_CHI_TIEU_CAP3, ChiTieuBO.TEN_CHI_TIEU_CAP3},
                {ChiTieu.FIELD_TYPE, ChiTieuBO.TYPE},
                {ChiTieu.FIELD_LA_CHI_TIEU_AO, ChiTieuBO.LA_CHI_TIEU_AO},
                {ChiTieu.FIELD_CHO_PHEP_TINH_TONG, ChiTieuBO.CHO_PHEP_TINH_TONG},
                {ChiTieu.FIELD_DON_VI_ID,ChiTieuBO.DON_VI_ID},
                {ChiTieu.FIELD_DON_VI_TINH, ChiTieuBO.DON_VI_TINH},
                {ChiTieu.FIELD_RECORD_COUNT, ChiTieuBO.RECORD_COUNT}
            };

            return mapDictionary;
        }
    }
}
